
var _util = require('util/util.js');
var _order_service = require('service/order-service.js');
var _account_servcie = require('service/account-service.js');
var listTemplate = require('./index.string');

require('page/common/header/index.js');

var confirmOrder = {
    listDate : {
        productList : {},
        itemList    : {}
    },
    init: function () {
        this.bindEvents();
        this.loadAccountInfo();
        return this;
    },
    bindEvents: function () {
    },
    confirmclict: function () {
        console.log("confirmclict");
        _order_service.paidOrder(
            function(res) {
                    _account_servcie.checkLogin(
                        function(res) {
                            _account_servcie.myAccount(
                                function(res) {
                                    window.location.href = "./cart-myCart.html?id=myCart";
                                },
                                function(errMsg) {
                                    console.log('error_mycart...');
                                }
                            );                   
                        },
                        function(errMsg) {
                            console.log('weidenglu...');
                        }
                )
            },
            function(errMsg) {
            }
        )
    },
    loadAccountInfo : function(){
        var _this = this;
        _order_service.confOrder(  
            function(res){
                //console.log(res);
                _this.listDate.itemList = res;
                _this.listDate.productList = res.lineItems;
                var result = _util.renderHtml(listTemplate, {ListData : _this.listDate});
                $('#conFirm').html(result);
                document.getElementById("confirm").addEventListener("click",function(){
                    _this.confirmclict();
                });
            },
            function(errMsg) {
                // 对应Thymeleaf中账号未登录的相关逻辑
                console.log('errMsg...'+errMsg);
            }
        );
    }
}
module.exports =confirmOrder.init();